/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Vue;

import Modele.Partie;
import javax.swing.JPanel;
import javax.swing.*;
import Modele.QCMModele;
import Modele.Questionnaire;
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.Map;

/**
 *
 * @author sirine
 */
public class QCM extends JPanel {

    // Variables declaration - do not modify                     
    private java.awt.Button button1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private java.awt.Label label1;
    //private ActionEvent modeJeu;
    private boolean reponseSaisie;
    private JPanel panelJoueur;
    private JLabel textJoueur;
    private JPanel panelQuestion;
    private JPanel panel_bas;
    private JPanel panelRadio;
    private ButtonGroup groupeBouton;
    private Partie partie;
    private QCMModele modele;
    private Questionnaire q = new Questionnaire("qcm");
    private int i;
    // End of variables declaration  

    public Questionnaire getQuestionnaire() {
        return q;
    }

    public QCM(Partie p) throws IOException {
        q.selectionQuestions("QCM");
        modele = q.questionSuivante();
        jLabel1 = new javax.swing.JLabel();
        groupeBouton = new ButtonGroup();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        groupeBouton.add(jRadioButton1);
        groupeBouton.add(jRadioButton2);
        groupeBouton.add(jRadioButton3);
        button1 = new java.awt.Button();
        label1 = new java.awt.Label();
        panelJoueur = new JPanel();
        textJoueur = new JLabel();
        panelQuestion = new JPanel(new GridLayout(3, 1));
        panelRadio = new JPanel();
        panel_bas = new JPanel();
        partie = p;
        jLabel1.setText(modele.getEnonce());
//        jRadioButton1.setText("reponse 1");
//
//        jRadioButton2.setText("reponse 2");
//
//        jRadioButton3.setText("reponse 3");
        Map<String, Boolean> reponses = modele.getReponses();
        System.out.println("modele getrep : " + modele.getReponses());
        for (String mapKey : reponses.keySet()) {
            i++;
            System.out.println("i : " + i);
            // utilise ici hashMap.get(mapKey) pour accéder aux valeurs
            Boolean reponse = reponses.get(mapKey);
            if (i == 1) {
                jRadioButton1.setText(mapKey);
                jRadioButton1.setActionCommand(""+reponses.get(mapKey));
            }
            if (i == 2) {
                jRadioButton2.setText(mapKey);
                jRadioButton2.setActionCommand(""+reponses.get(mapKey));
            }
            if (i == 3) {
                jRadioButton3.setText(mapKey);
                jRadioButton3.setActionCommand(""+reponses.get(mapKey));
            }


        }
        i = 0;
        button1.setLabel("Question suivante");

        label1.setText("ISIGame");
        panelQuestion.add(label1);
        panelQuestion.add(jLabel1);
        actualiserInfosJoueur();
        panelJoueur.add(textJoueur);
        //initialiserJRadioButton();
        panelRadio.add(jRadioButton1);
        panelRadio.add(jRadioButton2);
        panelRadio.add(jRadioButton3);
        panelQuestion.add(panelRadio);
        this.setLayout(new GridLayout(3, 1));
        this.add(panelJoueur);
        this.add(panelQuestion);
        this.add(panel_bas);

        //modeJeu = new ActionEvent(this, 1, "");

        //QCMListener listener = new QCMListener(this);
        //button1.addActionListener(listener);

        /*javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
         this.setLayout(layout);
         layout.setHorizontalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
         .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
         .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addGap(36, 36, 36))
         .addGroup(layout.createSequentialGroup()
         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
         .addGap(53, 53, 53)
         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
         .addComponent(jRadioButton1)
         .addGap(18, 18, 18)
         .addComponent(jRadioButton2)
         .addGap(18, 18, 18)
         .addComponent(jRadioButton3))
         .addComponent(jLabel1)))
         .addGroup(layout.createSequentialGroup()
         .addContainerGap()
         .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
         .addContainerGap(92, Short.MAX_VALUE)));
         layout.setVerticalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
         .addContainerGap()
         .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addGap(64, 64, 64)
         .addComponent(jLabel1)
         .addGap(56, 56, 56)
         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
         .addComponent(jRadioButton1)
         .addComponent(jRadioButton2)
         .addComponent(jRadioButton3))
         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
         .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
         .addGap(37, 37, 37)));*/
        //this.add(panel_bas);

    }

    public JLabel getjLabel1() {
        return jLabel1;
    }

    public JRadioButton getjRadioButton1() {
        return jRadioButton1;
    }

    public JRadioButton getjRadioButton2() {
        return jRadioButton2;
    }

    public JRadioButton getjRadioButton3() {
        return jRadioButton3;
    }

    public Button getButton1() {
        return button1;
    }

    public JPanel getPanel_bas() {
        return panel_bas;
    }

    public void setPanel_bas(JPanel panel_bas) {
        this.panel_bas = panel_bas;
    }

    public void actualiserInfosJoueur() {
        textJoueur.setText("Pseudo: " + partie.getJoueur()
                + " score: " + partie.getScore());
        System.out.println("le score est bien de " + partie.getScore());
        this.revalidate();
    }
    /*
     private void initialiserJRadioButton() {
     jRadioButton1.addActionListener(new ActionListener() {
     @Override
     public void actionPerformed(ActionEvent event) {
     modeJeu = event; 
     }
     });

     jRadioButton2.addActionListener(new ActionListener() {
     @Override
     public void actionPerformed(ActionEvent event) {
     modeJeu = event;
     }
     });
        
     jRadioButton3.addActionListener(new ActionListener() {
     @Override
     public void actionPerformed(ActionEvent event) {
     modeJeu = event;
     }
     });
     }

     public ActionEvent getModeJeu() {
     return modeJeu;
     }
     */

    public Partie getPartie() {
        return partie;
    }

    public ButtonGroup getGroupeBouton() {
        return groupeBouton;
    }
    
    
}
